/*
Copyright 2021 Loggie Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package result

import "github.com/loggie-io/loggie/pkg/core/api"

type DefaultResult struct {
	err    error
	status api.Status
	es     []api.Event
}

func Success() *DefaultResult {
	return NewResult(api.SUCCESS)
}

func Fail(err error) *DefaultResult {
	return &DefaultResult{
		err:    err,
		status: api.FAIL,
	}
}

func Drop() *DefaultResult {
	return &DefaultResult{
		status: api.DROP,
	}
}

func DropWith(err error) *DefaultResult {
	return &DefaultResult{
		status: api.DROP,
		err:    err,
	}
}

func NewResult(state api.Status) *DefaultResult {
	return &DefaultResult{
		status: state,
	}
}

func (dr *DefaultResult) WithError(err error) *DefaultResult {
	dr.err = err
	return dr
}

func (dr *DefaultResult) Events() []api.Event {
	return dr.es
}

func (dr *DefaultResult) Status() api.Status {
	return dr.status
}

func (dr *DefaultResult) Batch() api.Batch {
	return nil
}

func (dr *DefaultResult) ChangeStatusTo(status api.Status) {
	dr.status = status
}

func (dr *DefaultResult) Error() error {
	return dr.err
}
